def BellmanFord(edges_value, N, start):
    min_dist = [float('inf')]*(N+1)
    min_dist[start] = 0
    flag = False
    for i in range(N+1):
        
        for s, t, value in edges_value:
            if i<N:
                if min_dist[s] != float('inf') and min_dist[s]+value < min_dist[t]:
                    min_dist[t] = min_dist[s]+value
            else:
                if min_dist[s] != float('inf') and min_dist[s]+value < min_dist[t]:
                    flag = True
        
    return min_dist, flag

                
def main():
    N, M = map(int, input().split())
    edges_value = []
    for i in range(M):
        s, t, value = map(int, input().split())
        edges_value.append([s, t, value])
        
    min_dist, flag = BellmanFord(edges_value, N, 1)
    if flag:
        print('circle')
    else:
        if min_dist[-1] == float('inf'):
            print("unconnected")
        else:
            print(min_dist[-1])

main()